package com.atguigu.common.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * className: Md5
 * description:
 * date: 2023/4/15 0015-18:54
 * <p>
 * project: guigu-oa-parent
 * package: com.atguigu.common.utils
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
public final class Md5 {

    public static String encrypt(String strSrc) {
        try {
            char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
                    '9', 'a', 'b', 'c', 'd', 'e', 'f'};
            byte[] bytes = strSrc.getBytes();
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(bytes);
            bytes = md.digest();
            int j = bytes.length;
            char[] chars = new char[j * 2];
            int k = 0;
            for (byte b : bytes) {
                chars[k++] = hexChars[b >>> 4 & 0xf];
                chars[k++] = hexChars[b & 0xf];
            }
            return new String(chars);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new RuntimeException("MD5加密出错！！+" + e);
        }
    }

    public static void main(String[] args) {
        System.out.println(Md5.encrypt("111111"));
    }
}
